<template>
  <div>
    <el-form :model="formData" :rules="formRules" label-width="120px">
      <el-form-item label="节点 id" prop="id">
        <el-input v-model="formData.id" />
      </el-form-item>
      <el-form-item label="节点名称" prop="name">
        <el-input v-model="formData.name" />
      </el-form-item>
      <el-form-item label="节点描述" prop="documentation">
        <el-input v-model="formData.documentation" />
      </el-form-item>
      <el-form-item label="执行监听器" prop="executionListener">
        <el-badge :value="executionListenerLength">
          <el-button @click="dialogName = 'executionListenerDialog'">编辑</el-button>
        </el-badge>
      </el-form-item>
      <el-form-item label="异步" prop="async">
        <el-switch v-model="formData.async" active-text="是" inactive-text="否" />
      </el-form-item>
    </el-form>
    <executionListenerDialog
      v-if="dialogName === 'executionListenerDialog'"
      :element="element"
      :modeler="modeler"
      @close="finishExecutionListener"
    />
  </div>
</template>

<script setup>
  import { ref, watch, defineProps } from 'vue';
  import mixinPanel from '../../common/mixinPanel';
  import mixinExecutionListener from '../../common/mixinExecutionListener';
  import { commonParse } from '../../common/parseElement';

  const props = defineProps({
    modeler: {
      type: Object,
      required: true,
    },
    element: {
      type: Object,
      required: true,
    },
    categorys: {
      type: Array,
      default: () => [],
    },
  });

  const formData = ref({});
  const formRules = ref({
    id: [{ required: true, message: 'Id 不能为空' }],
  });

  const { updateProperties } = mixinPanel(props.modeler, props.element, formData);
  const { executionListenerDialog, executionListenerLength, dialogName, finishExecutionListener } =
    mixinExecutionListener(props.element);

  watch(
    () => formData.value.async,
    (val) => {
      if (val === '') val = null;
      updateProperties({ 'flowable:async': val });
    },
  );

  formData.value = commonParse(props.element);
</script>

<style scoped lang="scss"></style>
